var bussFirefightingIndex = {
    init:function () {
        var id = $.getUrlParam('id');
        var option = kaValue.getUrl("getSysFirefightingdevice");
        option.url = option.url + "/" + id;
        option.async = false;
        option.success = function (re) {
            if (re.code == 200) {
                kaData = re.data;
                $("#name").html(kaData.name);//设备名称
                $("#produceDate").html(`<div id="produceDateDivData">` + kaData.produceDate + `</div>
                    <div id="produceDateDiv" style="display: none;">
                        <input type="text" value="` + kaData.produceDate + `" class="layui-input" id="produceDate" placeholder="yyyy-MM-dd">
                    </div>`);//生产日期：
                $("#periodOfValidity").html(kaData.periodOfValidity);//有效期：
                $("#rechargepowderdate").html(`<div id="rechargepowderdateLaydateDivData">` + kaData.rechargepowderdate + `</div>
                    <div id="rechargepowderdateLaydateDiv" style="display: none;">
                        <input type="text" value="` + kaData.rechargepowderdate + `" class="layui-input" id="rechargepowderdateLaydate" placeholder="yyyy-MM-dd">
                    </div>`);//重填日期
                $("#rechargePowderNum").html(kaData.rechargePowderNum);//充粉次数：
                $("#lastSpotCheckNumDate").html(kaData.lastSpotCheckNumDate);//上次点检：
                $("#spotChecker").html(kaData.spotChecker);//点检人：
            }
        }
        option.error = function (re) {
            return false;
        }
        ka.ajax(option);
    },
    nameClick: function (that) {
        var name = $(that).text();
        layer.prompt({title: name}, function(value, index, elem){
            if(value === '') return elem.focus();
            var id = $.getUrlParam('id');
            var option = kaValue.getUrl("SysFirefightingdeviceGetInfo");
            option.url = option.url + "/" + id;
            option.async = false;
            option.success = function (re) {
                if (re.code == 200) {
                    kaData = re.data;
                    $("#produceDateDiv").show();
                    $("#produceDateDivData").hide();
                    var option = kaValue.getUrl("SysFirefightingdeviceEdit");
                        option.data = {
                            "id": id,
                            "name": value
                        };
                        option.async = false;
                        option.success = function (re) {
                            if (re.code == 200) {
                                window.location.reload();
                            }
                        }
                        option.error = function (re) {
                            return false;
                        }
                        ka.ajax(option);
                }
            }
            option.error = function (re) {
                return false;
            }
            ka.ajax(option);
            layer.close(index);
        });
    },
    produceDateClick: function () {
        var id = $.getUrlParam('id');
        var option = kaValue.getUrl("SysFirefightingdeviceGetInfo");
            option.url = option.url + "/" + id;
            option.async = false;
            option.success = function (re) {
                if (re.code == 200) {
                    kaData = re.data;
                    $("#produceDateDiv").show();
                    $("#produceDateDivData").hide();
                    layui.laydate.render({
                        elem: '#produceDate',
                        value: $("#produceDate").val(),
                        done: function(value, date, endDate){
                            var option = kaValue.getUrl("SysFirefightingdeviceEdit");
                            option.data = {
                                "id": id,
                                "produceDate": value
                            };
                            option.async = false;
                            option.success = function (re) {
                                if (re.code == 200) {
                                    window.location.reload();
                                }
                            }
                            option.error = function (re) {
                                return false;
                            }
                            ka.ajax(option);
                        }
                    });
                }
            }
            option.error = function (re) {
                return false;
            }
            ka.ajax(option);
    },
    rechargepowderClick:function () {
        var id = $.getUrlParam('id');
        var option = kaValue.getUrl("SysFirefightingdeviceGetInfo");
            option.url = option.url + "/" + id;
            option.async = false;
            option.success = function (re) {
                if (re.code == 200) {
                    kaData = re.data;
                    $("#rechargepowderdateLaydateDiv").show();
                    $("#rechargepowderdateLaydateDivData").hide();
                    layui.laydate.render({
                        elem: '#rechargepowderdateLaydate',
                        value: $("#rechargepowderdateLaydate").val(),
                        done: function(value, date, endDate){
                            var option = kaValue.getUrl("SysFirefightingdeviceRechargepowder2");
                            option.data = {
                                "id": id,
                                "rechargepowderdate": value
                            };
                            option.async = false;
                            option.success = function (re) {
                                if (re.code == 200) {
                                    window.location.reload();
                                }
                            }
                            option.error = function (re) {
                                return false;
                            }
                            ka.ajax(option);
                        }
                    });
                }
            }
            option.error = function (re) {
                return false;
            }
            ka.ajax(option);
    },
    lookLastSpotCheckNumClick:function () {
        var spotCheckerHtml = `
            <table lay-filter="parse-table-demo" class="layuiTableX">
        `;
        var id = $.getUrlParam('id');
        var option = kaValue.getUrl("lookLastSpotCheckNumBussExternal");
        option.data = {
            "id":id
        }
        option.async = false;
        option.success = function (re) {
            if (re.code == 200) {
                kaData = re.data
                var fps = kaData.fps;
                var list = kaData.list;
                var theadHtml = `<th lay-data="{field:'nameX'}">日期</th>`;
                var tbodyHtml = "";
                var number = fps.length;
                for(var i in fps){
                    theadHtml = theadHtml + `<th lay-data="{field:'name`+i+`'}">` + fps[i].produceName + `</th>`;
                }
                theadHtml = theadHtml + `<th lay-data="{field:'nameXx'}">签名</th>`;
                for(var i in list){
                    tbodyHtml = tbodyHtml + `
                        <tr>
                            <td>` + list[i].name + `</td>
                    `
                    if(number >= 1){
                        tbodyHtml = tbodyHtml + `<td>` + (list[i].fbk1Id!=null?"已点检":"") + `</td>`;
                    }
                    if(number >= 2){
                        tbodyHtml = tbodyHtml + `<td>` + (list[i].fbk2Id!=null?"已点检":"") + `</td>`;
                    }
                    if(number >= 3){
                        tbodyHtml = tbodyHtml + `<td>` + (list[i].fbk3Id!=null?"已点检":"") + `</td>`;
                    }
                    if(number >= 4){
                        tbodyHtml = tbodyHtml + `<td>` + (list[i].fbk4Id!=null?"已点检":"") + `</td>`;
                    }
                    if(number >= 5){
                        tbodyHtml = tbodyHtml + `<td>` + (list[i].fbk5Id!=null?"已点检":"") + `</td>`;
                    }
                    if(number >= 6){
                        tbodyHtml = tbodyHtml + `<td>` + (list[i].fbk6Id!=null?"已点检":"") + `</td>`;
                    }
                    if(number >= 7){
                        tbodyHtml = tbodyHtml + `<td>` + (list[i].fbk7Id!=null?"已点检":"") + `</td>`;
                    }
                    if(number >= 8){
                        tbodyHtml = tbodyHtml + `<td>` + (list[i].fbk8Id!=null?"已点检":"") + `</td>`;
                    }
                    if(number >= 9){
                        tbodyHtml = tbodyHtml + `<td>` + (list[i].fbk9Id!=null?"已点检":"") + `</td>`;
                    }
                    if(number >= 10){
                        tbodyHtml = tbodyHtml + `<td>` + (list[i].fbk10Id!=null?"已点检":"") + `</td>`;
                    }
                    if(number >= 11){
                        tbodyHtml = tbodyHtml + `<td>` + (list[i].fbk11Id!=null?"已点检":"") + `</td>`;
                    }
                    if(number >= 12){
                        tbodyHtml = tbodyHtml + `<td>` + (list[i].fbk12Id!=null?"已点检":"") + `</td>`;
                    }
                    if(number >= 13){
                        tbodyHtml = tbodyHtml + `<td>` + (list[i].fbk13Id!=null?"已点检":"") + `</td>`;
                    }
                    if(number >= 14){
                        tbodyHtml = tbodyHtml + `<td>` + (list[i].fbk14Id!=null?"已点检":"") + `</td>`;
                    }
                    if(number >= 15){
                        tbodyHtml = tbodyHtml + `<td>` + (list[i].fbk15Id!=null?"已点检":"") + `</td>`;
                    }
                    if(number >= 16){
                        tbodyHtml = tbodyHtml + `<td>` + (list[i].fbk16Id!=null?"已点检":"") + `</td>`;
                    }
                    if(number >= 17){
                        tbodyHtml = tbodyHtml + `<td>` + (list[i].fbk17Id!=null?"已点检":"") + `</td>`;
                    }
                    if(number >= 18){
                        tbodyHtml = tbodyHtml + `<td>` + (list[i].fbk18Id!=null?"已点检":"") + `</td>`;
                    }
                    if(number >= 19){
                        tbodyHtml = tbodyHtml + `<td>` + (list[i].fbk9Id!=null?"已点检":"") + `</td>`;
                    }
                    if(number >= 20){
                        tbodyHtml = tbodyHtml + `<td>` + (list[i].fbk20Id!=null?"已点检":"") + `</td>`;
                    }
                    tbodyHtml = tbodyHtml + `<td>` + (list[i].djr!=null?list[i].djr:"") + `</td>`;
                    tbodyHtml = tbodyHtml + `</tr>`;
                }
                spotCheckerHtml = spotCheckerHtml + `
                 <thead>
                    <tr>
                        ` + theadHtml + `
                    </tr>
                     </thead>
                     <tbody>
                    `+tbodyHtml+`
                    </tbody>
                    </table>
                `;
                layer.open({
                    type: 1, // page 层类型
                    area: ['100%', '100%'],
                    title: `<div style="font-size: 18px;text-align: center;color: #000;font-weight: 900;margin-left: 10%;">灭火器检查记录卡</div>`,
                    shade: 0.6, // 遮罩透明度
                    anim: 0, // 0-6 的动画形式，-1 不开启
                    content: spotCheckerHtml,
                    success:function () {
                        layui.table.init('parse-table-demo', {});
                    }
                  });
            }
        }
        option.error = function (re) {
            return false;
        }
        ka.ajax(option);
    },
    spotCheckerClick:function () {
        var spotCheckerHtml = `
            <form class="layui-form layui-form-pane" action="">
                <div class="layui-form-item">
                    <label class="layui-form-label">点检日期</label>
                    <div class="layui-input-block">
                        <input type="text" name="name" id="name" readonly autocomplete="off" placeholder="yyyy-MM-dd" class="layui-input">
                    </div>
                </div>
                 
        `;
        var id = $.getUrlParam('id');
        var option = kaValue.getUrl("lookLastSpotCheckNum");
        option.data = {
            "id":id
        }
        option.async = false;
        option.success = function (re) {
            if (re.code == 200) {
                kaData = re.data
                var fps = kaData.fps;
                var theadHtml = ``;
                var num = 1;
                var title = ``;
                if(fps.length > 0){
                    theadHtml = theadHtml + `
                    <input type="hidden" name="deviceId" value="` + fps[0].deviceId + `" />
                    `;
                    title = fps[0].deviceName
                }
                for(var i in fps){
                    var lengthsize = fps[i].produceName.length;
                    theadHtml = theadHtml + `
                        <div class="layui-form-item" pane>
                            <label class="layui-form-label" style="width: ` + (lengthsize * 20 + 40 ) + `px;">` + fps[i].produceName + `</label>
                                <div class="layui-input-block">
                                <input type="radio" name="fbk`+num+`Id" value="` + fps[i].produceId + `" title="点检" checked>
                                <input type="radio" name="fbk`+num+`Id" value="" title="不点检">
                            </div>
                        </div>
                    `;
                    num++;
                }
                spotCheckerHtml = spotCheckerHtml + theadHtml + `
                    <div class="layui-form-item">
                        <label class="layui-form-label">点检人</label>
                        <div class="layui-input-block">
                            <input type="text" name="djr" id="djr" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <button class="layui-btn" lay-submit lay-filter="demo2">确认</button>
                        <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                    </div>
                </form>
                `;
                layer.open({
                    type: 1, // page 层类型
                    area: ['100%', '100%'],
                    title: `<div style="font-size: 18px;text-align: center;color: #000;font-weight: 900;margin-left: 10%;">消防设备(` + title + `)点检</div>`,
                    shade: 0.6, // 遮罩透明度
                    anim: 0, // 0-6 的动画形式，-1 不开启
                    content: spotCheckerHtml,
                    success:function () {
                        layui.laydate.render({
                            elem: '#name'
                          });
                        layui.form.render();
                        layui.form.on('submit(demo2)', function(data){
                            var field = data.field; // 获取表单字段值
                            // 显示填写结果，仅作演示用
                            layer.alert(JSON.stringify(field), {
                              title: '当前填写的字段值'
                            });
                            // 此处可执行 Ajax 等操作
                            var option = kaValue.getUrl("SysFirefightinglistAdd");
                                option.async = false;
                                option.data = field;
                                option.success = function (re) {
                                    if (re.code == 200) {   
                                        window.location.reload();
                                    }
                                }
                                option.error = function (re) {
                                    return false;
                                }
                                ka.ajax(option);
                            return false; // 阻止默认 form 跳转
                        });
                    }
                  });
            }
        }
        option.error = function (re) {
            return false;
        }
        ka.ajax(option);
    }
}